# -*- coding: UTF-8 _*_
import os
import time

import uiautomator2 as u2

from common import appbase
from common.appbase import APPBase
from common.readconfig import ReadConfig
from config.config import base_path

device = ReadConfig.parse_yaml(filename='config/appconfig.yaml', key='base.device')
appname = ReadConfig.parse_yaml(filename='config/appconfig.yaml', key='base.appname')
# print(device)
d = u2.connect_usb(device)
x=d.current_app()
print(x)
d.app_start('com.tmri.app.main',stop=True)
sess=d.session()
sess.implicitly_wait(30)
time.sleep(10)
sess.watcher.when('是否确认退出?').press('back')
sess.watcher.start()
time.sleep(5)
sess.press('back')
sess(resourceId="com.tmri.app.main:id/rb_service").click()
time.sleep(2)
sess(resourceId="com.tmri.app.main:id/guide_layout").click()
time.sleep(2)




















































































# # d.set_fastinput_ime(False)
#
# d.app_start('com.hpbr.bosszhipin')
# app = d.session("com.hpbr.bosszhipin")
# # print(app)
# # app.settings['wait_timeout'] = 20
# t=APPBase(app)
# x=d(resourceId='com.hpbr.bosszhipin:id/tv_position_name')
# print(x.get_text())
# x=t.findElements(locator=('resourceId', 'com.hpbr.bosszhipin:id/tv_position_name'))
# for i in x:
    # print(t.gettextbyele(ele=i))
    # app.press('back')
    # time.sleep(1)
# x=app(resourceId='com.hpbr.bosszhipin:id/tv_position_name').all()


# time.sleep(10)

# for i in range(0,10):
# ele = t.findElements(locator=('resourceId', 'com.hpbr.bosszhipin:id/tv_position_name'))
# for i in ele:
#         # print(type(ele[i]))
#         # print(i.click())
#
#     print(t.gettextbyele(i))
#     t.clickbyele(i)
#     d.press("back")
# info=d.app_current()
# print(info)
# d.screen_on()
# d.unlock()
# d.app_start('com.tencent.mm',stop=True)
# d.xpath('//*[@resource-id="vivo:id/resolver_slide"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]').click()
# time.sleep(20)
# d(resourceId="com.tencent.mm:id/j5t").click()
# d.xpath('//*[@resource-id="com.tencent.mm:id/j4t"]/android.widget.RelativeLayout[1]').set_text('李隆庆')
# d.xpath(
#     '//*[@resource-id="com.tencent.mm:id/j6x"]/android.widget.RelativeLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]').click()
# # time.sleep(10)
# # d.set_fastinput_ime(False)
# d(resourceId="com.tencent.mm:id/kii").click()
# d.send_keys('阿斯蒂芬')
# # d(resourceId="com.tencent.mm:id/kii").clear_text('adsfadsfasdf')
# d(resourceId="com.tencent.mm:id/b8k").click()


# print(d(resourceId='com.hpbr.bosszhipin:id/tv_position_name').get_text(timeout=3))
# t=APPBase(d)
# d.implicitly_wait(10)
# x=d(resourceId='com.hpbr.bosszhipin:id/tv_position_name111').wait()
# print(x)
# ele=d(resourceId='com.hpbr.bosszhipin:id/tv_position_name')
# ele=t.findElements(locator=('resourceId','com.hpbr.bosszhipin:id/tv_position_name'))
# print(ele)
# print(type(ele))
# x=t.gettexts(ele)
# print(x)
# time.sleep(10)
# # d.swipe_ext('up',0.7)
# # time.sleep(10)
# # d.swipe_ext('up',0.7)
# x,y=d.window_size()
# d.swipe(x*0.5,y*0.9,x*0.5,y*0.3)
# time.sleep(10)
# ele=t.findElements(locator=('resourceId','com.hpbr.bosszhipin:id/tv_position_name'))
# x=t.gettexts(ele)
# print(x)
# locator=('resourceId','com.hpbr.bosszhipin:id/tv_position_name')

# def findElements(pagename='', elename='', doc='查找元素组',**kwargs):
#     for key,value in kwargs.items():
#         print(key)
#         print(value)


# findElements(A=1,B=2)

# x,y=d.window_size()
# for i in range(0,10):
#     ele = t.findElements(locator=('resourceId', 'com.hpbr.bosszhipin:id/tv_position_name'))
#     for i in range(0,len(ele)):
#         # print(type(ele[i]))
#         # print(ele[i].click())
#         t.clickeles(ele[i])
#         d.press("back")
#     d.swipe(x * 0.5, y * 0.9, x * 0.5, y * 0.3)
# # jpg_path = base_path + ReadConfig.parse_yaml(filename='config/webconfig.yaml', key='path.jpg')
# # if  os.path.exists(jpg_path):
# #     print('文件加不存在')
# #     os.mkdir(jpg_path)



'''监控 弹框样例'''
# d.watcher('test').when('//*[@resource-id="com.hpbr.bosszhipin:id/work_expectblue_float_view"]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]').when('//*[@resource-id="com.hpbr.bosszhipin:id/iv_close"]').click()
# # d.watcher.start()
# d.watcher.start(2.0)
# time.sleep(10)

'''12123 监控弹框'''
# d.app_start('com.tmri.app.main',stop=True)
# sess=d.session()
# sess.implicitly_wait(30)
# time.sleep(10)
# sess.watcher.when('是否确认退出?').press('back')
# sess.watcher.start()
# time.sleep(5)
# sess.press('back')
# sess(resourceId="com.tmri.app.main:id/rb_service").click()
# time.sleep(2)
# sess(resourceId="com.tmri.app.main:id/guide_layout").click()
# time.sleep(2)

'''设置session，将session作为 driver，并修改默认等待时间'''
# app = d.session("com.hpbr.bosszhipin")
# print(app)
# app.settings['wait_timeout'] = 20
# t=APPBase(app)

'''获取当前 app'''
# print(d.current_app())

'''启动应用前先停止该应用'''
# d.app_start('com.ss.android.ugc.aweme.lite',stop=True)


